package org.example.practiceexamples.component;

import lombok.RequiredArgsConstructor;
import org.example.practiceexamples.interceptor.AdminInterceptor;
import org.example.practiceexamples.interceptor.ManageInterceptor;
import org.example.practiceexamples.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
@RequiredArgsConstructor
public class WebMvcConfig implements WebMvcConfigurer {

    private final LoginInterceptor loginInterceptor;
    private final AdminInterceptor adminInterceptor;
    private final ManageInterceptor ManageInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns("/api/**")
                .excludePathPatterns("/api/login");

        registry.addInterceptor(adminInterceptor).addPathPatterns("/api/admin/**");

        registry.addInterceptor(ManageInterceptor).addPathPatterns("/api/manage/**");
    }


//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        registry.addMapping("/**")
//                .allowedOrigins("*")
//                .allowedHeaders("*")
//                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH")
//                .allowCredentials(true)
//                .maxAge(3600);
//    }
//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        registry.addMapping("/api/**")
//                .allowedOrigins("http://localhost:5173")
//                .allowedMethods("GET", "POST", "DELETE");
//    }
}
